package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.saas.domain.entity.FineClueScriptEntity;
import com.xbongbong.saas.domain.entity.RuleClueEntity;
import com.xbongbong.saas.domain.entity.ext.ClueEntityExt;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;


public interface ClueModel extends IModel<ClueEntityExt> {
    /**
     * 线索数据单条查询
     * @param key 主键ID
     * @param corpid 公司ID
     */
    ClueEntityExt getByKey(Long key, String corpid);

    /**
     * 通过json_set语句改变data的多个值
     * 该值必须是data下一级的值
     * 并且更新更新时间
     *
     * @param corpid 公司id
     * @param id 数据的id
     * @param map 需要更新的值
     */
    void jsonsetNoSubById(String corpid, Long id, Map<String,Object> map) throws XbbException;

    /**
     * 单个删除
     * @param id
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer deleteByKey(Long id,String corpid) throws XbbException;

    /**
     * 批量删除
     * @param idIn id列表
     * @param corpid 公司id
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer deleteBatch(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 批量修改
     * @param corpid
     * @param dataIdList
     * @param map
     * @param refreshPolicy 刷新策略
     * @throws XbbException
     */
    void updateBatchNoSub(String corpid, List<Long> dataIdList, Map<String,Object> map, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    Integer restoreBatch(List<Long> dataIdList, String corpid, Integer del, String publicAttr) throws XbbException;

    /**
     * 彻底删除
     * @param dataIdList 数据id列表
     * @param corpid 公司id
     * @param del 删除标识
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer thoroughDeleteBatch(List<Long> dataIdList, String corpid, Integer del) throws XbbException;

    Integer updateBatch(List<UpdateDataEntity> updateDataList, String corpid) throws XbbException;

    Integer updateBatch(List<UpdateDataEntity> updateDataList, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    List<ClueEntityExt> getByKeys(List<Long> keys, String corpid);

    /**
     * @Description: 获取员工主负责的线索列表
     * @param corpid 公司id
     * @param idIn
     * @return
     */
    List<RuleClueEntity> getMainClueList4Rule(String corpid, List<Long> idIn);

    @Override
    List<ClueEntityExt> findEntitys(Map<String, Object> param);
    /**
     * @Description: 获取员工主负责的线索列表
     * @param corpid 公司id
     * @param userId 员工id
     * @param statusStr 线索状态
     * @param pageNum 分页数
     * @param pageSize 分页大小
     * @param orderField 排序字段
     * @param sortList 排序方式 排序字段的顺序 [1, 2, 3] [1, 3, 2]
     * @param clueIdIn 线索id集合
     * @return
     */
    List<RuleClueEntity> getMainClueListByUserId(String corpid, String userId, String statusStr, Integer pageNum, Integer pageSize, String orderField, List<Integer> sortList, List<Long> clueIdIn) throws XbbException;

    List<RuleClueEntity> getClueListByIdIn(String corpid, List<Long> clueIdIn);


    /**
     * @Description: 获取员工主负责的线索数
     * @param corpid 公司id
     * @param userId 员工id
     * @return
     */
    Integer getMainClueCountByUserId(String corpid, String userId);

    /**
     * @Description: 获取员工主负责的客户数
     * @param corpid 公司id
     * @param userId 员工id
     * @param statusStr
     * @return

     */
    Integer getMainClueCountByUserId(String corpid, String userId, String statusStr);


    /**
     * 按手机号查询线索
     * @param phone 用于判重的手机号
     * @param corpid 公司ID
     * @author youli.chen
     * @date 2019/1/23 20:27
     * @since v1.0
     * @return CustomerEntityExt
     */
    ClueEntityExt getByPhone(String corpid, String phone) throws XbbException;

    ClueEntityExt getByPhoneIncloudRecycled(String corpid, String phone) throws XbbException;

    /**
     * 按手机号查询线索
     *
     * @param corpid    公司ID
     * @param phoneList 号码集合
     * @return 线索集合
     * @throws XbbException 异常
     */
    List<ClueEntityExt> listByInPhone(String corpid, List<String> phoneList,boolean dontQueryDel) throws XbbException;
    /**
     * 编辑时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     */
    void formatUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 编辑时将获取数据格式化
     *
     * @param formDataUpdateGetDTO saas编辑数据
     * @param result               要返回的jsonobject
     * @throws XbbException 业务异常
     */
    void formatData(SaasAnalysisDataDTO formDataUpdateGetDTO, JSONObject result) throws XbbException;


    Integer updateTime(Long id,String corpid) throws XbbException ;

    void insertBatch(List<PaasFormDataEntity> insertList) throws XbbException;

    /**
     * 刷精线索脚本使用
     *
     * @param corpid
     * @param pidIn
     * @return
     */
    List<FineClueScriptEntity> getListByPids(String corpid, List<String> pids);
}
